package czStvDpds.network;

import czStvDpds.centrallogic.Logic;
import czStvDpds.graphics3D.GraphicsEndProcessor;
import java.net.DatagramPacket;
import java.net.InetAddress;
import czStvDpds.network.*;
import java.util.concurrent.LinkedTransferQueue;

/**
 *
 * @author Martin Strouhal,JT
 */
public class ServerManager implements GraphicsEndProcessor {

    
    
    
    
    private InetAddress adresaServeru = null;
    Logic logic = null;
    ServerManager sm;
    ThreadReceiver receiver = null;
    PacketMaker paketMaker = null;
    Sender s = null;
    PotvrzeniThread potvrzenithread=null;

    
    public ServerManager(InetAddress adresa, Logic l) {
        adresaServeru = adresa;
        logic = l;        
        initNetworkPart();
        logic.addGraphicsEndProcessor(this);
        logic.setPacketMaker(paketMaker);
    }

    private void initNetworkPart() {
        
        s = new Sender(adresaServeru);                      
        potvrzenithread=new PotvrzeniThread(s);  
        receiver = new ThreadReceiver(logic,potvrzenithread);
        receiver.start();
        paketMaker = new PacketMaker(s,potvrzenithread);
        
                              
        
        
        
        
               
         
        

    }

    @Override
    public void graphicsEnded() {
        s.ukonciSpojeni();
        receiver.ukonciVlakno();
        potvrzenithread.ukonciVlakno();
        
    }
}
